<?php
/*
 *2015.7.13 add dragon.hu shopinformation 
 * */

defined('BASEPATH') or die('forbidden');

class Shopinformation_Controller extends Controller
{
	private $conn;
	private $nameConn;
	private $nameList;
	private $inc;
	private $professionList; //职业列表
	private $storeList; //商店列表
	private $objectList; //物品列表
	
	
	function _init()
	{
		check_level(50, segment(0), segment(1), segment(2, 'index'));
		set_time_limit(0);
		$this->inc = $this->config['inc'];
		$this->professionList = $this->inc['type_proffessionid'];
		
		$areanum = $_SESSION['area_selected_id'];
		if($areanum == '')
		{
			echo "<script>alert('".translate('C_SELECT_AREA_TEXT')."');</script>";
			return;
		}	
		$this->nameConn = getTmpDbConnect(PLATFORM_ALL, 'all', $areanum, DBTYPE_GAMESERVER);
		$this->nameConn->query("SELECT id, name FROM player");
		while ($n = $this->nameConn->get_array('default'))
		{
			$this->nameList[$n['id']] = $n['name'];
		}
		$this->nameConn->free_all();
		$this->storeList = array('0' => '工会商店', '1' => '竞技场商店', '2' => '荣耀之巅商店', '3' => '熔炼商店');
		$this->objectList = get_type_object_db();
		
		$this->conn = getTmpDbConnect(PLATFORM_ALL, 'all', $areanum, DBTYPE_LOG);
	}
	
	function flexigrid()
	{
		list($colkey, $colsinfo, $where, $sortname, $sortorder, $offset, $rp, $page) = $this->common->get_flexigrid_params();
		$sql = "SELECT COUNT(*) AS num FROM exchange_shop WHERE {$where}";
		
		$one = $this->conn->one($sql);
		$total = $one['num'];
		$orderby = $sortname ? "ORDER BY {$sortname} {$sortorder}" : "";
		$sql = "SELECT {$colsinfo} FROM exchange_shop WHERE {$where} $orderby LIMIT {$offset}, {$rp}";
		$this->conn->query($sql);
		while ($n = $this->conn->get_array('default'))
		{
			$n['profession'] = $this->professionList[$n['profession']]."(".$n['profession'].")";
			$n['role_id'] = $this->nameList[$n['role_id']]."(".$n['role_id'].")";
			$n['shop_type'] = $this->storeList[$n['shop_type']]."(".$n['shop_type'].")";
			$n['item'] = $this->objectList[$n['item']]."(".$n['item'].")";
			
			$rows[] = array('id' => $n['id'], 'cell' => $n);
		}
		$result = array('page' => $page, 'total' => $total, 'rows' => $rows);
		
		echo json_encode($result);
	}
	
	function index()
	{
		$this->view->display('logtrade/shopinformation/index');	
	}
}